class Solution {
public:
    int findLUSlength(vector<string>& strs)
    {
        sort(strs.begin(), strs.end(), [](string& x, string& y)
            {
                return x.size() < y.size();
            });

        int ans = -1;
        int n = strs.size();
        vector<bool> flag(n, true);
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)//long
            {
                int cur1 = 0;
                int cur2 = 0;
                while (cur1 < strs[i].size() && cur2 < strs[j].size())
                    if (strs[i][cur1] == strs[j][cur2++]) cur1++;
                if (cur1 == strs[i].size()) flag[i] = false;
                if (strs[i] == strs[j]) flag[i] = flag[j] = false;
            }
        }
        for (int i = 0; i < n; i++) if (flag[i]) ans = max(ans, (int)strs[i].size());
        return ans;
    }
};